﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;

namespace MP3Ganizer.Controls.Converters
{
    public class PercentageToColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;
            double status = 0;
            if (!double.TryParse(value.ToString(), out status))
                return null;
            double colorR, colorG, colorB = 0;
            colorR = status < 50 ? 255 : (2 - (status / 50)) * 255;
            colorG = status > 50 ? 255 : (status / 50) * 255;
            colorB = 0;
            SolidColorBrush brush = new SolidColorBrush(Color.FromRgb((byte)colorR, (byte)colorG, (byte)colorB));
            return brush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }

}
